<!-- 个人信息 -->
<template>
	<view class="container">
		<view class="card">
			<u-form :model="form" ref="uForm" label-width="132">
				<u-form-item label="昵&emsp;&emsp;称" prop="name">
					<view slot="label"></view>
					<u-input v-model="form.name" />
				</u-form-item>
				<u-form-item label="手&ensp;机&ensp;号" prop="phone">
					<view slot="label">手&ensp;机&ensp;号</view>
					<u-input v-model="form.phone" />
				</u-form-item>
				<u-form-item label="单位信息" prop="jigou">
					<u-input v-model="form.jigou" />
				</u-form-item>
			</u-form>
		</view>

		<view class="btn-box u-flex u-row-center u-col-center">
			<button class="u-reset-button logout-btn" @tap="submit">
				完成注册
			</button>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	import Auth from '@/shopro/permission/index.js';
	import wechat from '@/shopro/wechat/wechat';

	export default {
		components: {},
		data() {
			return {
				platform: this.$platform.get(),
				form: {
					name: '',
					phone: '',
					jigou: '',
				},
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],
					phone: [{
						validator: (rule, value, callback) => {
							return this.$u.test.mobile(value);
						},
						message: '手机号码不正确',
						// 触发器可以同时用blur和change
						trigger: ['change', 'blur'],
					}],
					jigou: [{
						required: true,
						message: '请输入单位简称',
						trigger: ['change', 'blur'],
					}]
				}
			};
		},
		computed: {
			...mapGetters(['userInfo', 'authType'])
		},
		onReady() {

		},
		methods: {
			bind() {
				this.$http('user.bind_phone', {
					username: this.form.name,
					mobile: this.form.phone,
					jigou: this.form.jigou
				}).then((res) => {
					console.log(res);
					if (res.code === 1) {
						uni.showToast({
							icon: 'none',
							title: '绑定成功！'
						})
						setTimeout(() => {
							uni.reLaunch({
								url:'/pages/news/work?type=login'
							})
						}, 800)
					}
				})
			},
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						this.bind()
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.btn-box {
		.logout-btn {
			width: 710rpx;
			height: 100rpx;
			line-height: 100rpx;
			border: 1rpx solid #E77817;
			border-radius: 20rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #fff;
			background-color: #E77817;
		}
	}
</style>